package com.hsnn.medstgmini.base.dict.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hsnn.medstgmini.base.dict.dao.DicDrugspecLogDao;
import com.hsnn.medstgmini.base.dict.model.DicDrugspec;
import com.hsnn.medstgmini.base.dict.model.DicDrugspecLog;
import com.hsnn.medstgmini.base.dict.service.DicDrugspecLogManager;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseDate;


/**
 * 基础库 数据字典 规格字典 维护记录接口实现类SERVICE
 * @author hss@njhsnn
 * 2015年6月9日
 */
@Service()
public class DicDrugspecLogManagerImpl  implements DicDrugspecLogManager {

	private DicDrugspecLogDao dicDrugspecLogDao;
	
	 @Autowired
	    public void setDicDrugspecLogDao(DicDrugspecLogDao dicDrugspecLogDao) {
	        this.dicDrugspecLogDao = dicDrugspecLogDao;
	    }
	 
		/**
		 *  基础库 数据字典 规格字典 维护记录添加
		 * @param dicDrugspecLog
		 */
	@Transactional
	@Override
	public boolean add(DicDrugspecLog dicDrugspecLog) {
	 return this.dicDrugspecLogDao.add(dicDrugspecLog);
	}

	/**
	 * 基础库 数据字典 规格字典 维护记录查询所有及条件查询
	 * @param dicDrugspecLog
	 * @return
	 */
	@Transactional
	@Override
	public List<DicDrugspecLog> queryDicDrugspecLogByName(
			Pagination page,DicDrugspecLog dicDrugspecLog) {
		return  dicDrugspecLogDao.queryDicDrugspecLogByName(page,dicDrugspecLog);
	}
	@Override
	public Pagination queryDicDrugspecLogList(Pagination page){
		page= dicDrugspecLogDao.queryDicDrugspecLogList(page);
		List<Object> list=(List<Object>) page.getRows();
		List<DicDrugspecLog> data = new ArrayList<DicDrugspecLog>();
		if(list.size()>0){
			for(int i=0;i<list.size();i++){
				Object[] obj=(Object[]) list.get(i);
				DicDrugspecLog dsl = new DicDrugspecLog();
				DicDrugspec ds = new DicDrugspec();
				ds.setSpecCode(obj[0]==null?"":obj[0].toString());
				ds.setSpecName(obj[1]==null?"":obj[1].toString());
				dsl.setDicDrugspecCode(ds);
				dsl.setSpecCode(obj[2]==null?"":obj[2].toString());
				dsl.setSpecName(obj[3]==null?"":obj[3].toString());
				dsl.setStatus(Short.parseShort(obj[4].toString()));
				dsl.setUpdUser(obj[5]==null?"":obj[5].toString());
				dsl.setUpdDatetime(ParseDate.fromFullFormat(obj[6].toString()));
				dsl.setLogId(obj[7]==null?"":obj[7].toString());
				dsl.setDetail(obj[8]==null?"":obj[8].toString());
				data.add(dsl);
			}
		}
		page.setRows(data);
		return page;
	}

	/**
	 * 基础库 数据字典 剂型字典 根据id查询 规格 日志详情
	 * @param result
	 * @param dicDrugspecLog
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getDrugSpecHisDetail(Pagination page) {
		return dicDrugspecLogDao.getDrugSpecHisDetail(page);
	}
}
